package com.mtl.inmigrant.shoes;

import java.io.IOException;
import java.util.List;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.widget.ListView;

import com.google.api.services.plus.model.Activity;
import com.mtl.inmigrant.shoes.adapter.GPlusActivityAdapter;

public class LoginActivity extends android.app.Activity {

	private List<Activity> activities;
	private ListView list;
	private SharedPreferences prefs;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
	    if (android.os.Build.VERSION.SDK_INT > 9) {
	        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
	        StrictMode.setThreadPolicy(policy);
	      }
		try {
				setup();
				activities = ActivitiesFromGPlusHelper.searchActivitiesImmigrants(prefs);
				if (activities != null) 
					updateViews();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}

	private void setup() {
		setContentView(R.layout.activity_login);
		PreferenceManager.getDefaultSharedPreferences(this);
		list = (ListView) findViewById(R.id.list);
	}

	private void updateViews() {
		list.setAdapter(new GPlusActivityAdapter(this, activities));
	}

	
}
